<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="static/bootstrap-3.3.0/css/bootstrap.min.css" rel="stylesheet">
<link href="static/myCss/css/styles.css" rel="stylesheet">
<title>财务系统</title>
</head>
<body class="login-bg">
  	<div class="header">
	     <div class="container">
	        <div class="row">
	           <div class="col-md-12">
	              <!-- Logo -->
	              <div class="logo">
	                 <h1 style="text-align:center"><a>财务系统</a></h1>
	              </div>
	           </div>
	        </div>
	     </div>
	</div>

	<div class="page-content container">
		<div class="row">
			<div class="col-md-4 col-md-offset-4">
				<div class="login-wrapper">
			        <div class="box">
			            <div class="content-wrap">
			                <h6>登录</h6>
			                <input  id="username" name="username" class="form-control" type="text" placeholder="Username">
			                <input id="password" name="password" class="form-control" type="password" placeholder="Password" onkeydown="keyListener(event)">
			                <div class="action">
			                    <input class="btn btn-primary signup" value="Login" onclick="login();"/>
			                </div>           
			            </div>
			        </div>	       
			    </div>
			</div>
		</div>
	</div>
<script src="static/myCss/js/jquery-3.1.1.min.js"></script>
<script src="static/bootstrap-3.3.0/js/bootstrap.min.js"></script>
<script src="static/js/jquery.tips.js"></script>
<script src="static/zongdao/zongdao-1.0.js"></script>
<script src="static/layer/layer.js" ></script>
<script type="text/javascript">
/*按下enter键直接调用登录方法*/
function keyListener(event){ 
    if (event.keyCode === 13){ 
    	login();
    } 
  } 
/*登录方法*/
function login(){
	var username = $('#username').val();
	var password = $('#password').val();

	var l = ZD.msg.load();
	var fdata = {'username':username,'password':password, 'method':'finance.sys.user.login'};
	
	//获取URL
	var protocol = window.location.protocol;
	var host = window.location.host;
	var url = protocol + '//' + host + '/finance/router/rest';
	 fdata = JSON.stringify(fdata);
	$.ajax({
		url:url,
		data:fdata,
		type:"POST",
		async:false,
		dataType:"json",
		contentType:"application/json",
		beforeSend:function(request){
			request.setRequestHeader("login", "login");
		},
		success:function(res){
			ZD.msg.close(l);
			if(res.status == 0){
				/**登录成功...设置token**/
				ZD.ux.SetCookie(ZD.base.TOKEN, res.data.token, "s"+res.data.time);
				window.location.href = "index.jsp";
			}else{
				if(res.msg == 1){
					ZD.msg.alert("账号或密码不能为空.");
				}else if(res.msg == 2){
					ZD.msg.alert("账号或密码错误.");
				}else if(res.msg == 3){
					ZD.msg.alert("账号超出限制，请联系管理员");
				}else if(res.msg == 4){
					ZD.msg.alert("账号已被删除");
				}else{
					ZD.msg.alert(res.msg);
				}
			}
		},
		error:function(err){
			ZD.msg.close(l);
			ZD.msg.alert('连接错误，请稍后再试!');
		}
	});
	
	
}
</script>

</body>
</html>